close all
clear all
clc

fsine=61e6;
fchirp=60e6;
fs=80e6;
ts=1/fs;
fn=20e6;
N=1024;
T=N/fs;
B=8e6;
t=0:1/fs:T-1/fs;
u=B/T;
f=linspace(-fs/2,fs/2,N);

%input_sig=sin(2*pi*fsine*t); 
input_sig=sin(2*pi*fchirp*t+pi*u*t.^2);

figure(1)
subplot(211)
plot(t,input_sig);
xlim([0,0.5e-6]);
xlabel('t/s');
ylabel('Amptitude');
title('Input time domain');
subplot(212)
plot(f,abs(fftshift(fft(input_sig))));
xlabel('freq/Hz');
ylabel('Amptitude');
title('Input frequency domain');

local_i=cos(2*pi*fn*t);
local_q=sin(2*pi*fn*t);

figure(2)
subplot(211)
plot(t,local_i);
xlim([0,0.5e-6]);
xlabel('t/s');
ylabel('Amptitude');
title('NCO time domain');
subplot(212)
plot(f,abs(fftshift(fft(local_i))));
xlabel('freq/Hz');
ylabel('Amptitude');
title('NCO frequency domain');

window=chebwin(51,40);
[b,a]=fir1(50,2*B/fs,window);
figure(3)
freqz(b,1,[0:fs/N:fs/2],fs); 

I=local_i.*input_sig;
Q=local_q.*input_sig;
f_I=filter(b,a,I);
f_Q=filter(b,a,Q);

figure(4)
subplot(211)
plot((0:N-1)*ts,f_I);
xlabel('t/s');
ylabel('Amptitude');
title('I路');
subplot(212)
plot((0:N-1)*ts,f_Q);
xlabel('t/s');
ylabel('Amptitude');
title('Q路');

NCO=f_I+1j.*f_Q;
 
figure(5)
subplot(211)
plot(f,abs(fftshift(fft(I))));
xlabel('freq/Hz');
ylabel('Amptitude');
title('DDC frequency domain');
subplot(212)
plot(f,abs(fftshift(fft(NCO))));
xlabel('freq/Hz');
ylabel('Amptitude');
title('Baseband frequency domain');